package com.ll.beautymall.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.ll.beautymall.bean.Category;
import com.ll.beautymall.ui.nine.view.NineContentFragment;

import java.util.List;

/**
 * Created by Administrator on 2016/10/27.
 */
public class NineAdapter extends FragmentPagerAdapter {
    private List<NineContentFragment> list;
    private List<Category> titles;
    private FragmentManager manager;


    public NineAdapter(FragmentManager fm) {
        super(fm);
        manager = fm;
    }

    public void replaceFragment(int index, NineContentFragment fragment) {
        this.list.remove(index);
        this.list.add(fragment);
        manager.beginTransaction().remove(list.get(index)).add(fragment, String.valueOf(index)).commit();
        notifyDataSetChanged();
    }


    public void setData(List<NineContentFragment> list, List<Category> titles) {
        this.list = list;
        this.titles = titles;
        notifyDataSetChanged();
    }

    @Override
    public Fragment getItem(int position) {
        return list != null ? list.get(position) : null;
    }

    @Override
    public int getCount() {
        return list != null ? list.size() : 0;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles != null ? titles.get(position).getTitle() : null;
    }
}
